This page last changed on May 31, 2006 by tcarlson.

Axis integrates with Mule meaning you can expose Mule components as Axis services and invoke Axis Services from mule. To expose a Mule component as an Axis service all you have to do is set the components receive endpoint to An Axis URL, i.e.

<mule-descriptor name="echoService"
     inboundEndpoint="axis:http://localhost:81/services"
     implementation="org.mule.components.simple.EchoComponent">
</mule-descriptor>

When Mule starts, the service will be available on http://localhost:81/services/echoService. The Echo component class implements the EchoService interface that has a single method called echo that accepts a single parameter string.

Invoking Web Services

There are two ways of invoking webservices from Mule.

  1. Programmatically using the Mule Client
  2. As part of the event flow of a UMO Component

Each method is described in detail in the following sections.

Invoking Services with the MuleClient

To invoke Echo Service using the Mule Client, use the following -

TestEchoService.java
public static void main(String[] args)
{
    MuleClient client = new MuleClient();
    UMOMessage result = client.send
        ("axis:http://localhost:81/services/echoService?method=echo", 
         "Hello!", null);
    System.out.println("Message Echoed is: " + result.getPayload());
    client.close();
}

Invoking Web Services from a Component

To invoke the Echo Service from a component you need to add an outbound endpoint to your component descriptor. The example shown below is a component that receives an event on vm://test.component, does some work on the event and then invokes or echo service.

<mule-descriptor name="test" implementation="com.foo.TestComponent">
    <inbound-router>
        <endpoint address="vm://test.component" synchronous="true"/>
    <inbound-router>
    <outbound-router>
        <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
            <endpoint address="
                 axis:http://localhost:81/services/echoService?method=echo"/>
        </router>
    </outbound-router>
</mule-descriptor>

The org.foo.TestComponent looks like -

org.foo.TestComponent
public class TestComponent implements Callable
{
    public Object onCall(UMOEventContext context) throws Exception
    {
        Object payload = context.getMessage().getPayload();

        //Do some work on the payload and return a string that will be
        //used by the outbound endpoint to invoke the echo service
        //...

        return payload.toString();
    }
}

If the Web service you are invoking takes more than one parameter, just return an array of parameters in your component.

When an event is published vm://test.component the onCall method will be called with the current event. After the onCall method executes, Mule will invoke the outbound endpoint for TestComponent with what is returned from the onCall method call.

Note that the vm://test.component endpoint has a parameter synchronous=true. This tells Mule to invoke requests from that endpoint in a single thread, making it a request/response style request. Thus the result of invoking the Echo Service (by invoking Test Component) will be returned to the callee who dispatched the event on vm://test.component.

When the TestEchoService is run you will see the following output -

Message Echoed is: Hello!
Using Quick Configuration

When testing it can be cumbersome to start a separate Mule server to test a service, so you can use the QuickConfigurationBuilder to start a server and register your service in your test code i.e.

QuickConfigurationBuilder builder = new QuickConfigurationBuilder();
builder.createStartedManager(true, "");
UMOEndpoint soapEndpoint = new MuleEndpoint("axis:http://localhost:81/services");
builder.registerComponent(EchoComponent.class.getName(), 
                          "echoService", soapEndpoint);

See Configuring Mule Programmatically for more information.

There are a couple of things to note about this demonstration -

  1. There is no need for a Servlet container as Mule is the container
  2. You don't need to specify a deployment WSDD for your service. All you need to do is specify an endpoint for the service and the rest is done for you.
  3. The MuleClient call will work just as well if the service you are invoking is hosted by an Axis instances running on Tomcat or any other Servlet Engine.

You will need to have the Axis jar and associated jars on your classpath, these ship with the Mule distribution.

Exposing Services

All service operations are exposed through interfaces implemented by your component. This means your component must implement at least one service interface. This is generally good practice anyway.

Axis without a Servlet Container

Using Axis with Mule means there is no need for a separate servlet container. When an axis endpoint such as 'axis:http://localhost:81/services' is declared, mule does a couple of things -

  • Creates an Axis Component in Mule. This is analogous to the AxisServlet, there is only one per Mule instance.
  • Creates a http connector for localhost:81 and registers it as a receiver for the Axis component.


Cannot resolve external resource into attachment.

Most web services are a lot more complex than the first example so the following sections will tell you how to configure the Axis instance and your services in more detail.

Configuring the Axis Server

In the previous example, a default Axis connector is created when the axis endpoint is processed by Mule. The Axis connector uses a default server configuration file called mule-server-config.wsdd. You can override this configuration by setting the serverConfig on the connector. This will allow you add additional Handlers, global configuration, etc.

<connector name="axisConnector" className="org.mule.providers.soap.axis.AxisConnector">
    <properties>
        <property name="serverConfig" value="./axis/axis-server-config.wsdd"/>
    </properties>
</connector>

If you use a custom server configuration remember to add the following handlers in the global configuration -

<requestFlow>
    <handler 
     type="java:org.mule.providers.soap.axis.extensions.MuleSoapHeadersHandler"/>
</requestFlow>
<responseFlow>
    <handler 
     type="java:org.mule.providers.soap.axis.extensions.MuleSoapHeadersHandler"/>
</responseFlow>

If you are configuring Mule from a container such as Spring, you can set the Axis server as a bean property on the connector and the serverConfig property is ignored.

You can list the Axis services in the same way you list services when Axis is hosted in a servlet container. To list services simply point your browser at the host and port of the axis endpoint -

http://localhost:81/

To view Axis version information go to -

http://localhost:81/Version?method=getVersion

To view the WSDL for the service go to-

http://localhost:81/Version?wsdl

Note that the Axis JWS feature is not supported by Mule.

Soap over Other Transports
You can configure Axis to send/receive soap requests over other transports such as Jms and Smtp. For more information see Axis Soap Transports.

For more information about customising Axis behaviour, Naming parameters, Message style options and more see Configuring Axis.

Document generated by Confluence on Nov 27, 2006 10:27